<template>
  <view class="chat-block">
	<view style="padding: 10rpx 40rpx 0 40rpx;">
		<u--textarea v-model="reason" placeholder="请输入审批意见" height='300'></u--textarea>
		<!-- <uni-easyinput :inputBorder="false" trim="all" type="textarea" v-model="reason" placeholder="请输入审批意见" /> -->
	</view>
	
	<view class="submit-button" @click="approve">
		<view style="background-color: #0087FC;" class="submit-block" v-if="status == 1">
			确认同意
		</view>
		<view style="background-color: #0087FC;" class="submit-block" v-if="status == 2">
			确认拒绝
		</view>
	</view>
	
	<u-toast ref="uToast"></u-toast>
  </view>
</template>

<script>
import { approval } from '@/api/flow'
import { getSpCount } from '@/api/flow.js'
export default {
	data() {
		return {
			title:'',
			status: '',
			type:'',
			tbId:undefined,
			id: undefined,
			reason:'',
			czId:''
		}
	},
	onLoad(option) {
		this.status = option.status
		this.type = option.type
		this.tbId = option.tbId
		this.czId = option.czId
	},
	methods: {
		async approve(){
			if(this.status == '2'&&this.reason == ''){
				this.$refs.uToast.show({
				  type: 'default',
				  message: '拒绝意见不能为空'
				})
				return
			}
			var params = {
				tbId:this.tbId,
				status:this.status,
				type:this.type,
				reason:this.reason
			}
			const { data } = await approval(params)
			if (data.code == 200) {
				uni.showToast({
					title: '提交成功'
				})
				this.getSpNum()
				setTimeout(() => {
					uni.navigateBack({
						delta: 2
					});
					const eventChannel = this.getOpenerEventChannel();
					eventChannel.emit('refreshPage', {
						id: this.czId,
					});
				}, 500)
			}else{
				uni.showToast({
					title: '审批失败',
					icon:'error'
				})
			}
		},
		async getSpNum(){
			const { data } = await getSpCount();
			if(data.code == 200){
				// #ifdef APP-PLUS
				plus.runtime.setBadgeNumber(data.data);
				// #endif
			}
		},
	}
}
</script>

<style lang="scss" scoped>
	.submit-button{
		height: 0 !important;
	}
// .option{
// 	display: flex;
// 	flex-direction: column;
// 	margin-bottom: 150rpx;
// 	margin-top: 118rpx;
// }
// .chat {
//   display: flex;
//   flex-direction: column;
//   margin-bottom: 150rpx;
//   margin-top: 88rpx;
// }
// .b-actions {
//   position: fixed;
//   width: 730rpx;
//   min-height: 150rpx;
//   left: 10rpx;
//   bottom: 0;
//   padding: 0 20rpx;
//   display: flex;
//   justify-content: center;
//   align-items: center;
// }
</style>
